package com.lancoo.znbkxx.ielts.aiysTrainPaper.aiysAnalysisPaper

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPreviewInfor
import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPreview.AibkPreviewAnswerSheetChildAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPreview.AibkPreviewAnswerSheetChildAdapter.onClickChildListener
import android.text.Html
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.R
import kotlinx.android.synthetic.main.aibk_adapter_answersheet_parent.view.*

/**
 * auther: 王国龙
 *  Date：2020.06.15
 * describe:
 */
class AibkPreviewAnswerSheetParentAdapter(
        val activity: AppCompatActivity,
        val paperPreviewInfor: PaperPreviewInfor
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View {
        return LayoutInflater.from(activity)
            .inflate(R.layout.aibk_adapter_answersheet_parent, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        var TypeIndex = paperPreviewInfor.TypeList[position].TypeIndex
        var TypeName = paperPreviewInfor.TypeList[position].TypeName
        var GenreName = paperPreviewInfor.TypeList[position].GenreName
        holder.convertView.TvTypeInfor.text = Html.fromHtml(activity.resources.getString(R.string.aibk_answersheet_ques_infor,
                LancooMethod.numberToChinese(TypeIndex), if (GenreName.isEmpty()) TypeName else GenreName))

        val adapterChild = AibkPreviewAnswerSheetChildAdapter(
                activity, paperPreviewInfor, position
        )
        holder.convertView.RvAnswerSheetChild.adapter = adapterChild
        adapterChild.setClickChildListener(object : onClickChildListener {
            override fun onClick(
                index_A: Int,
                index_B: Int,
                index_C: Int
            ) {
                clickParentListener!!.onClick(index_A, index_B,index_C)
            }
        })


    }

    override fun getItemCount(): Int {
        return paperPreviewInfor.TypeList.size
    }

    interface onClickParentListener {
        fun onClick(index_A: Int, index_B: Int, index_C: Int)
    }

    private var clickParentListener: onClickParentListener? = null

    fun setClickParentListener(clickParentListener: onClickParentListener?) {
        this.clickParentListener = clickParentListener
    }

//    fun position_return_A(paperPreviewInfor: PaperPreviewInfor, position: Int): Int {
//        var index_A = 0
//        var positionX = -1
//        var typeListSize = paperPreviewInfor.typeList.size
//        outLoop@ for (a in 0 until typeListSize) {
//            var quesListSize = paperPreviewInfor.typeList[a].quesList.size
//            for (b in 0 until quesListSize) {
//                positionX += 1
//                if (positionX == position) {
//                    index_A = a
//                    break@outLoop
//                }
//            }
//        }
//        return index_A
//    }

}